/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-07-01 12:03:25
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-07-01 12:03:29
 * @FilePath: \keep_motion_api\models\product\productActivity.model.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// 产品活动模型
const productActivitySchema = new Schema({
  name: { type: String, required: true },
  type: {
    type: String,
    enum: ["discount", "flash_sale", "bundle", "gift", "course_promotion"],
    required: true
  },
  discount_type: { 
    type: String, 
    enum: ['percentage', 'fixed', 'buy_one_get_one', 'free_shipping'] 
  },
  discount_value: Number,
  start_date: { type: Date, required: true },
  end_date: { type: Date, required: true },
  products: [{
    type: Schema.Types.ObjectId, 
    ref: 'Product' 
  }],
  courses: [{
    type: Schema.Types.ObjectId,
    ref: 'Course'
  }],
  conditions: {
    min_purchase: Number,
    member_level: {
      type: String,
      enum: ["bronze", "silver", "gold", "diamond"]
    },
    user_tags: [String]
  },
  limits: {
    usage_per_user: Number,
    total_usage: Number,
    stock_limit: Number
  },
  status: {
    type: String,
    enum: ["scheduled", "active", "ended", "cancelled"],
    default: "scheduled"
  },
  stats: {
    views: { type: Number, default: 0 },
    participation: { type: Number, default: 0 },
    conversion_rate: Number
  },
  banner_image: String,
  description: String,
  terms_and_conditions: String
});

module.exports = mongoose.model('ProductActivity', productActivitySchema);
